package com.xt.base.action;

import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.userdetails.UserDetails;

import com.xt.base.model.system.User;
import com.xt.base.service.LoginService;

public class LoginAction extends BaseAction{
	private static final long serialVersionUID = -4983266271922670220L;
	private LoginService loginService;
	
	public String login(){
		log.info("go in LoginAction.login method.");
		SecurityContext ctx = SecurityContextHolder.getContext();
		if (ctx != null) {
			Authentication auth = ctx.getAuthentication();
			if (auth != null && auth.getPrincipal() != null
					&& auth.getPrincipal() instanceof UserDetails) {
				UserDetails ud = (UserDetails)auth.getPrincipal();
				User user = this.loginService.reLoadUserInfo(ud.getUsername(), ud.getPassword());
				this.setSessionAttr(SESSIONCURRENTUSER, user);
			}
		}
		
		return SUCCESS;
	}


	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
}
